<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 

class Myclass {

    public function get_list_type($type)
    {
    	$CI =& get_instance();
    	$CI->load->model('Company_model', 'company');
		
		$companies = $CI->company->get_list_type($type);
		
		shuffle($companies);
		
		$CI->load->model('Intern_type_model', 'intern_type');
		
		foreach ($companies as &$company) {
			$company = $this->_update_info($company);			
		}
		
		//show_error(1);
		//print_r($companies);
		
		//show_error("");
		return $companies;
    }
	
	public function get_list_area($areaid)
    {
    	$CI =& get_instance();
    	$CI->load->model('Company_model', 'company');
		
		$companies = $CI->company->get_list_area($areaid);
		
		shuffle($companies);
		
		$CI->load->model('Intern_type_model', 'intern_type');
		
		foreach ($companies as &$company) {
			$company = $this->_update_info($company);
			
		}
		
		//print_r($companies);
		
		//show_error("");
		return $companies;
    }
	
	public function get_list_what($whatid)
    {
    	$CI =& get_instance();
    	$CI->load->model('Company_model', 'company');
		
		$companies = $CI->company->get_list_what($whatid);
		
		shuffle($companies);
		
		$CI->load->model('Intern_type_model', 'intern_type');
		
		foreach ($companies as &$company) {
			$company = $this->_update_info($company);
			
		}
		
		//print_r($companies);
		
		//show_error("");
		return $companies;
    }
	
	public function get_list_all()
    {
    	$CI =& get_instance();
    	$CI->load->model('Company_model', 'company');
		
		$companies = $CI->company->get_list_all();
		
		shuffle($companies);
		
		$CI->load->model('Intern_type_model', 'intern_type');
		
		foreach ($companies as &$company) {
			$company = $this->_update_info($company);
			
		}
		
		//print_r($companies);
		
		//show_error("");
		return $companies;
    }
	
	function _update_info($company){
		$CI =& get_instance();
		
		$meta = $CI->company->get_company_meta_info($company->id, "work_con, salary, hitokoto");
			
		$company->work_con = mb_substr($meta->work_con, 0, 50);
		$company->salary = mb_substr($meta->salary, 0, 20);
		$company->hitokoto = mb_substr($meta->hitokoto, 0, 70);
		
		$company->type = $CI->intern_type->strid_to_strname($company->type);
		$company->type = explode(",", $company->type);
		
		// get the comment
		$images = explode(",", $company->images);
		$img_cmt = explode(",", $company->img_cmt);
		$n = count($images);	$m = count($img_cmt);
		if ($m >= $n+1) $company->img_cmt = $img_cmt[$n];
		else $company->img_cmt = "";
		
		return $company;
	}
}

/* End of file Someclass.php */